package main

import (
	"log"
	"net"
	"os"

	driver "cloudea.com/k8s-csi-fs/driver"
	proto "cloudea.com/k8s-csi-fs/driver/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

func main() {
	//listener, err := net.Listen("tcp", ":50051")
	endpoint := driver.CSIEndPoint
	os.Remove(endpoint)
	listener, err := net.Listen("unix", endpoint)
	if err != nil {
		log.Fatalf("打开端口错误: %v", err)
	}
	server := grpc.NewServer()
	proto.RegisterHelloServiceServer(server, &driver.HelloServer{})
	proto.RegisterIdentityServer(server, &driver.IdentityServer{})
	proto.RegisterControllerServer(server, &driver.ControllerServer{})
	proto.RegisterNodeServer(server, &driver.NodeServer{})
	reflection.Register(server)
	log.Printf("grpc服务已创建: " + endpoint)
	if err := server.Serve(listener); err != nil {
		log.Fatalf("服务创建失败: %v", err)
	}
}
